import './index.scss'
import { newChooseGoodsPoints } from '../../api/shoppingMall/chooseGoods'

export default {
  name: 'choose-goods-points',
  props: {
    isGetChooseData: { // 是否开始返回数据
      type: Boolean,
      default: false
    },
    clickNum: {
      type: Number,
      default: 1
    },
    isGetType: {
      type:String,
      default:''
    },
    channel:{
      type:Array,
      default:[]
    },
    activityTime:{
      type:Object,
      default:{}
    }
  },
  watch: {
    clickNum(val) {
      this.getGoodsTabel()
      console.log('val', val)
    },
    isGetChooseData() {
      if (!this.currentChooseGoods.length) {
        this.$message.error('请选择商品')
        return
      }
      this.$emit('chooseGoodsFun', {
        data: this.currentChooseGoods
      })
    }
  },
  data() {
    return {
      chooseParams: {
        // 积分商城场景
        campaignScene: '',
        channel: [2],
        pageNum: 1,
        pageSize: 20,
        startTime:'', // 活动开始时间
        endTime:'', // 活动结束时间
      },
      list: [],
      option: {
        height: 350,
        isPagination: true,
        isMenu: false,
        paginationTotal: 40,
        paginationCurrent: 1,
        paginationSize: 20,
        isSelection: true,
        column: [
          {
            label: '活动名称',
            prop: 'name',
            slotName: 'name',
            menuWidth: '100%',
            menuAlign: 'center'
          },
          {
            label: '开始时间 ~ 结束时间',
            prop: 'campaignTime',
            slotName: 'campaignTime',
            menuWidth: '100%',
            menuAlign: 'center'
          },
        ]
      },
      currentChooseGoods: []// 当前选择的
    }
  },
  created() {
    // this.getGoodsTabel()
  },
  mounted() {
    this.chooseParams.campaignScene = this.isGetType
    this.chooseParams.channel = this.channel
    this.getGoodsTabel()
  },
  methods: {
    // 获取商品信息
    getGoodsTabel() {
      newChooseGoodsPoints({...this.chooseParams,...this.activityTime}).then(res => {
        this.list = res.records
        this.option.paginationTotal = res.total
      })
    },
    // 选中信息
    selectionChange(ev) {
      console.log('ev',ev)
      ev.forEach(item => {
        item.goodsId = item.campaignVO.goodsId
      })
      this.currentChooseGoods = ev
    },
    // 分页
    currentChange(ev) {
      this.chooseParams.pageNum = ev.data.current
      this.chooseParams.pageSize = ev.data.size
      this.getGoodsTabel()
    }
  }
}
